import {deleteMyReceive,
  downloadMyReceive,
  addPreDownload,
  queryDirTreeList,
  receivefilesList,
  receivefilesDelete,
  moveReceiveFile,
  previewFile,
  downloadFiles,
  downloadBwdaOnlineEdit,
  queryDatadictList,
} from '@/services/workspace';

export default {
  namespace: 'receiveModel',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},

  },

  effects: {

    * remove({payload, callback}, {call, put}) {
      const response = yield call(deleteMyReceive, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback();
      }
    },

    //预下载
    * addPreDownload({payload, callback}, {call, put}) {
      const response = yield call(addPreDownload, payload);
      if (callback) callback(response);
    },
    //查询目录组织树
    * queryDirTreeList({payload, callback}, {call, put}) {
      const response = yield call(queryDirTreeList, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'saveDirTreeList',
        payload: response,
      });
      }
    },

     //我的接受
    * receivefilesList({payload, callback}, {call, put}) {
      const response = yield call(receivefilesList, payload);
      if(response&&response.result=='ok'){
        yield put({
          type: 'save',
          payload: response,
        });
      }

    },
    * queryHideFunctions({payload, callback,}, {call, put}) {
      const response = yield call(queryDatadictList, payload);
      if (callback) callback(response);
    },

    * delete({payload, callback}, {call, put}) {
      const response = yield call(receivefilesDelete, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'savedelete',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    * moveFile({payload, callback}, {call, put}) {
      const response = yield call(moveReceiveFile, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'savemoveFile',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    * previewFile({payload, callback}, {call, put}) {
      const response = yield call(previewFile, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'savepreviewFile',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    * downloadFiles({payload, callback}, {call, put}) {
      const response = yield call(downloadFiles, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'savedownloadFiles',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    * downloadBwdaOnlineEdit({payload, callback}, {call, put}) {
      const response = yield call(downloadBwdaOnlineEdit, payload);
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    saveDirTreeList(state, action) {
      return {
        ...state,
        dirTreeList: action.payload.data,
      };
    },

  },
};
